<!-- 审核表单 -->

<template>
  <el-dialog
    :model-value="dialogFormVisible"
    :destroy-on-close="true"
    title="NFT发行状态"
    width="450px"
    @close="emits('closeDialog')"
  >
    <el-form
      ref="dialogFormRef"
      :model="dialogForm"
      :rules="rules"
      :label-width="formLabelWidth"
    >
      <el-form-item label="排序数字" prop="sort">
        <el-input v-model="dialogForm.sort" />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="dialogForm.status" placeholder="状态">
          <el-option label="下架" value="0" />
          <el-option label="上架" value="1" />
        </el-select>
      </el-form-item>

      <el-form-item label="id" style="display: none">
        <el-input v-model="dialogForm.issue_id" disabled />
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="emits('cancel')">取消</el-button>
        <el-button
          type="primary"
          @click="submit(dialogForm)"
          :loading="btnLoading"
        >
          提交
        </el-button>
      </span>
    </template>
  </el-dialog>
</template>
<script setup>
import { ref } from "vue";
const dialogFormRef = ref(null);

defineProps({
  dialogFormVisible: {
    type: Boolean,
    default: false,
  },
  dialogForm: {
    type: Object,
    default: {
      issue_id: "",
      sort: "",
      status: "",
    },
  },
  btnLoading: {
    type: Boolean,
    default: false,
  },
});
const emits = defineEmits(["closeDialog", "cancel", "submitForm"]);

const formLabelWidth = "120px";
// 校验
const rules = {
  status: [{ required: true, message: "请选择一个状态", trigger: "blur" }],
  sort: [{ required: true, message: "请添加一个排序数字", trigger: "blur" }],
};
// 提交
const submit = (dialogForm) => {
  dialogFormRef.value
    .validate()
    .then(async () => {
      try {
        const param = Object.assign({}, dialogForm);
        param.status = Number(param.status);
        emits("submitForm", param);
      } catch (error) {
        console.log(error);
      }
    })
    .catch((error) => {
      console.log(error);
    });
};
</script>
